package com.sunday.gateway.mock.security.webflux.login.controller;

import com.sunday.common.core.remoting.rest.response.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@Slf4j
@RestController
public class IndexController {

    @GetMapping("/")
    public Mono<RestResponse<Authentication>> index() {
        Mono<RestResponse<Authentication>> authMono = ReactiveSecurityContextHolder.getContext()
                .map(SecurityContext::getAuthentication)
                .doOnNext(auth -> log.info("{}", auth))
                .map(RestResponse::ok);
        return authMono;
    }

}